//
//  SCCertificateUploadStyleCell.m
//  Shuaiche
//
//  Created by xiangtao on 2024/3/21.
//  Copyright © 2024 ShuaiChe. All rights reserved.
//

#import "SCCertificateUploadStyleCell.h"
#import "UIImageView+SCwebImage.h"

@implementation SCCertificateUploadStyleCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    self.driveLicenseFrontCloseBtn.hidden = YES;
    self.driveLicenseBackCloseBtn.hidden = YES;
    
    self.driveLicenseFrontImageView.layer.cornerRadius = 4;
    self.driveLicenseFrontImageView.layer.masksToBounds = YES;
    self.driveLicenseBackImageView.layer.cornerRadius = 4;
    self.driveLicenseBackImageView.layer.masksToBounds = YES;
    
    self.driveLicenseFrontImageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickDriveLicenseFrontAction)];
    [self.driveLicenseFrontImageView addGestureRecognizer:tapGesture];
    
    self.driveLicenseBackImageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapBackGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickDriveLicenseBackAction)];
    [self.driveLicenseBackImageView addGestureRecognizer:tapBackGesture];
}

- (void)setFrontModel:(SCCarAddImageItemModel *)frontModel
{
    _frontModel = frontModel;
    if (_frontModel.imageUrlPath) {
        [_driveLicenseFrontImageView sc_setImageWithPath:_frontModel.imageUrlPath];
        _driveLicenseFrontCloseBtn.hidden = NO;
    } else if (_frontModel.image) {
        _driveLicenseFrontImageView.image = _frontModel.image;
        _driveLicenseFrontCloseBtn.hidden = NO;
    } else {
        _driveLicenseFrontImageView.image = [UIImage imageNamed:@"car_img_add"];
        _driveLicenseFrontCloseBtn.hidden = YES;
    }
}

- (void)setBackModel:(SCCarAddImageItemModel *)backModel
{
    _backModel = backModel;
    if (_backModel.imageUrlPath) {
        [_driveLicenseBackImageView sc_setImageWithPath:_backModel.imageUrlPath];
        _driveLicenseBackCloseBtn.hidden = NO;
    } else if (_backModel.image) {
        _driveLicenseBackImageView.image = _backModel.image;
        _driveLicenseBackCloseBtn.hidden = NO;
    } else {
        _driveLicenseBackImageView.image = [UIImage imageNamed:@"car_img_add"];
        _driveLicenseBackCloseBtn.hidden = YES;
    }
}

- (void)clickDriveLicenseFrontAction {
    if (self.delegate && [self.delegate respondsToSelector:@selector(SCCertificateUploadStyleCellDidAddFrontDriveLicense)]) {
        [self.delegate SCCertificateUploadStyleCellDidAddFrontDriveLicense];
    }
}
- (IBAction)clickDriveLicenseFrontCloseAction:(id)sender {
    if (self.delegate && [self.delegate respondsToSelector:@selector(SCCertificateUploadStyleCellDidDeleteFrontDriveLicense)]) {
        [self.delegate SCCertificateUploadStyleCellDidDeleteFrontDriveLicense];
    }
}

- (void)clickDriveLicenseBackAction {
    if (self.delegate && [self.delegate respondsToSelector:@selector(SCCertificateUploadStyleCellDidAddBackDriveLicense)]) {
        [self.delegate SCCertificateUploadStyleCellDidAddBackDriveLicense];
    }
}

- (IBAction)clickDriveLicenseBackCloseAction:(id)sender {
    if (self.delegate && [self.delegate respondsToSelector:@selector(SCCertificateUploadStyleCellDidDeleteBackDriveLicense)]) {
        [self.delegate SCCertificateUploadStyleCellDidDeleteBackDriveLicense];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
